#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <ctime>
#define ldb long double
#define LL long long
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int INF = 1 << 30;
using namespace std;

int n, m;
int edges, first[1510], end[5000], next[5000], beg[5000];
ldb cost[5000];
ldb d[2][1010], f[1010];
int p[2][1010];


void addEdge(int i, int j, ldb cst)
{
	next[edges] = first[i];
	beg[edges] = i;
	first[i] = edges;
	end[edges] = j;
	cost[edges] = cst;
	edges++;
}
int was[1011];
int st[1011];

void Load()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> f[i];
	}
	edges = 0;
	for (int i = 0; i <= n + 1; i++) first[i] = -1, was[i] = 0;
	int j, k;
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d", &j, &k);
		if (j != k)
		{
			addEdge(j, k, 0.5 - f[j]);
			addEdge(k, j, 0.5 - f[k]);
		}
	}
}



void out(int t, int j)
{
	int sz = 0;
	while (was[j] == 0)
	{
		was[j] = sz + 1;
		st[sz++] = j;
		j = beg[p[t][j]];
		t ^= 1;
	}
	for (int k = was[j] - 1; k < sz; k++)
		printf("%d ", st[k]);
	printf("-1");
	for (; sz; sz--)
	{
		was[st[sz - 1]] = 0;
	}
}

/*
void out(int i, int j)
{
	while (i != j)
	{
		printf("%d ", i / 2);
		if (i % 2 == 0)
			i = beg[p[i]] * 2 + 1;
		else i = beg[p[i]] * 2;
	}
	printf("-1");
}
*/

bool findCycle()
{
	int i, j;
	
	for (i = 0; i < n; i++)
	{
		d[0][i] = 0, d[1][i] = 1e42;
		p[0][i] = p[1][i] = -1;
	}
	bool flag = true;
	for (i = 0; flag && i < n; i++)
	{
		cerr << i << ":\n" ;
		flag = false;
		for (j = 0; j < edges; j++)
		{
			if (i % 2 == 0)
			{
				if (d[i & 1][beg[j]] < 1e42 - eps && d[(i & 1) ^ 1][end[j]] > d[i & 1][beg[j]] - f[beg[j]] + eps)
				{
					d[(i & 1) ^ 1][end[j]] = d[i & 1][beg[j]] - f[beg[j]];
					p[(i & 1) ^ 1][end[j]] = j;
					cerr << i << " : " << end[j] << " from " << beg[j] << " " << d[(i & 1) ^ 1][end[j]] << "\n";
					flag = true;
				}
			}
			else if (i % 2 == 1)
			{
				if (d[i & 1][beg[j]] < 1e42 - eps && d[(i & 1) ^ 1][end[j]] > d[i & 1][beg[j]] + 1 - f[beg[j]] + eps)
				{
					d[(i & 1) ^ 1][end[j]] = d[i & 1][beg[j]] + 1 - f[beg[j]];
					cerr << i << " : " << end[j] << " from " << beg[j] << " " << d[(i & 1) ^ 1][end[j]] << "\n";
					p[(i & 1) ^ 1][end[j]] = j;
					flag = true;
				}
			}
		}
	}
	for (int i = 0; i < 2; i++)
	for (j = 0; j < edges; j++)
	{
		if (i % 2 == 0)
		{
			if (d[i & 1][beg[j]] < 1e42 - eps && d[(i & 1) ^ 1][end[j]] > d[i & 1][beg[j]] - f[beg[j]] + eps)
			{
				printf("Bad Cycle: ");
				cerr << end[j] << " " << beg[j] << "\n";
				out(0, beg[j]);
				printf("\n");
				return true;
			}
		}
		else if (i % 2 == 1)
		{
			if (d[i & 1][beg[j]] < 1e42 - eps && d[(i & 1) ^ 1][end[j]] > d[i & 1][beg[j]] + 1 - f[beg[j]] + eps)
			{
				printf("Bad Cycle: ");
				cerr << end[j] << " " << beg[j] << "\n";
				out(1, beg[j]);
				printf("\n");
				return true;
			}
		}
	}
	return false;
}

	
void Solve()
{
	if (!findCycle())
		printf("Ok\n");
}

#define file "genind"
int main()
{
	#ifndef ONLINE_JUDGE
	freopen(file".in", "rt", stdin);
	freopen(file".out", "wt", stdout);
	#endif
	int T;
	cin >> T;
	srand(time(0));
	int i;
	for (i = 0; i < T; i++)
	{
		Load();
		Solve();
	}
	return 0;
}
